﻿var index = 0;
function addTab(ahref, txt) {
    var dhref = ahref.substring(0, ahref.lastIndexOf("/"));
    dhref = dhref.substring(dhref.lastIndexOf("/") + 1);
    if (dhref == "html" || dhref == "resume") {
        window.open(ahref, txt);
    } else {
        if (!$("#tt").tabs('exists', txt)) {
            index++;
            $('#tt').tabs('add', {
                title: txt,
                content: '<iframe scrolling="yes" frameborder="0" id="iframe_parent' + index + '" title="0" rel="' + txt + '"  src="' + ahref + '" width="100%" height="100%" style="width:100%;height:100%;"></iframe>',
                iconCls: 'icon-page',
                closable: true
            });
        } else {
            $("#tt").tabs('select', txt);
        }
    }
    tabClose();
}

function CloseTab(title) {
    if (title != "主页") {
        $('#tt').tabs('close', title);
    }
}

$(function () {
    var cli_menu = $(".easyui-linkbutton");
    $(".easyui-linkbutton").click(function () {
        $(".easyui-linkbutton").css("background", "url()");
        $(".easyui-linkbutton").css("border", "1px solid #fff");
        $(this).css("background", "url('../themes/default/images/button_plain_hover.png') repeat-x");
        $(this).css("border", "1px solid #7eabce");
        cli_menu = $(this);
    });
    $(".easyui-linkbutton").mouseover(function () {
        if ($(this).css("border-color") != cli_menu.css("border-color")) {
            $(this).css("background", "url('../themes/default/images/button_plain_hover.png') repeat-x");
            $(this).css("border", "1px solid #7eabcd");
        }
    });
    $(".easyui-linkbutton").mouseout(function () {
        if ($(this).css("border-color") != cli_menu.css("border-color")) {
            $(this).css("background", "url()");
            $(this).css("border", "1px solid #fff");
        }
    });
    tabClose();
    tabCloseEven();
    tab_reload();
});

function tab_reload() {
    try {
        $("#tt").tabs({
            onSelect: function (node) {
                var fra;
                var fra_id = $("[rel=" + node + "]").attr("Id");
                if (document.all) {//IE
                    fra = document.frames[fra_id];
                } else {//Firefox
                    fra = document.getElementById(fra_id);
                }
                if (fra.contentDocument) {
                    var doc = fra.contentDocument;
                    doc.location.href = fra.src
                } else {
                    fra.location.href = fra.location.href;
                }
            }
        });
    }
    catch (e) {
    }
}

function tabClose() {
    /*双击关闭TAB选项卡*/
    $(".tabs-inner").dblclick(function () {
        var subtitle = $(this).children("span").text();
        CloseTab(subtitle);
    })

    $(".tabs-inner").bind('contextmenu', function (e) {
        $('#mm').menu('show', {
            left: e.pageX,
            top: e.pageY
        });

        var subtitle = $(this).children("span").text();
        $('#mm').data("currtab", subtitle);

        return false;
    });
}
//绑定右键菜单事件
function tabCloseEven() {
    //关闭当前
    $('#mm-tabclose').click(function () {
        var currtab_title = $('#mm').data("currtab");
        CloseTab(currtab_title);
    })
    //全部关闭
    $('#mm-tabcloseall').click(function () {
        $('.tabs-inner span').each(function (i, n) {
            var t = $(n).text();
            CloseTab(t);
        });
    });
    //关闭除当前之外的TAB
    $('#mm-tabcloseother').click(function () {
        var currtab_title = $('#mm').data("currtab");
        $('.tabs-inner span').each(function (i, n) {
            var t = $(n).text();
            if (t != currtab_title)
                CloseTab(t);
        });
    });
    //关闭当前右侧的TAB
    $('#mm-tabcloseright').click(function () {
        var nextall = $('.tabs-selected').nextAll();
        if (nextall.length == 0) {
            //msgShow('系统提示','后边没有啦~~','error');
            alert('后边没有啦~~');
            return false;
        }
        nextall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            CloseTab(t);
        });
        return false;
    });
    //关闭当前左侧的TAB
    $('#mm-tabcloseleft').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        if (prevall.length == 0) {
            alert('到头了，前边没有啦~~');
            return false;
        }
        prevall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            CloseTab(t);
        });
        return false;
    });

    //退出
    $("#mm-exit").click(function () {
        $('#mm').menu('hide');
    })
}